const BaseStruct = {
  list: function (): Array<any> {
    var q = []
    for (var k in this) {
      if (typeof this[k] !== 'function') {
        q.push(this[k])
      }
    }
    return q
  },
  getByKey: function (key: string) {
    var [item] = this.list().filter(s => s.key == key.toUpperCase())
    return item
  },
  getByValue: function (v: string) {
    var [item] = this.list().filter(s => s.value == v)
    return item
  }
}

export function NewStruct(list: Array<any>) {
  var obj = Object.create(BaseStruct)
  list.forEach(item => {
    obj[item.key] = item
  })
  return obj
}
export default {
  name: 'struct',
  list: [{ funName: 'NewStruct', desc: '传入list生成struct对象' }],
  NewStruct
}
